﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EPiServer.Shell.ObjectEditing;
using EPiServer.Shell.ObjectEditing.EditorDescriptors;

namespace EPiBoost.Core.CustomProperties.EditorDescriptors
{
	[EditorDescriptorRegistration(TargetType = typeof(string), UIHint = Constants.UIHints.Language)]
  public class LanguageEditorDescriptor : EditorDescriptor
  {
      public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
      {
          SelectionFactoryType = typeof(LanguageSelectionFactory);
          ClientEditingClass = "epi.cms.contentediting.editors.CheckBoxListEditor";
          base.ModifyMetadata(metadata, attributes);
      }
  }
	[EditorDescriptorRegistration(TargetType = typeof(string), UIHint = Constants.UIHints.LanguageMulti)]
  public class LanguageEditorMultiDescriptor : EditorDescriptor
  {
      public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
      {
          SelectionFactoryType = typeof(LanguageSelectionFactory);
          ClientEditingClass = "epi.cms.contentediting.editors.SelectionEditor";
          base.ModifyMetadata(metadata, attributes);
      }
  }

	public class LanguageSelectionFactory : ISelectionFactory
	{
		public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
		{
			var languages = new List<SelectItem>();
			languages.Add(new SelectItem() {Value = "EN", Text = "English"});
			languages.Add(new SelectItem() {Value = "SW", Text = "Swahili"});
			languages.Add(new SelectItem() {Value = "PF", Text = "French Polynesia"});
			return languages;
		}
	}
}
